package contato.DAO;

import java.util.ArrayList;
import java.util.Date;

import javax.persistence.EntityManager;
import javax.persistence.Query;

import rta.dataacess.Cercanot;
import rta.dataacess.Confignot;
import rta.dataacess.Imei;
import rta.dataacess.Notifica;
import rta.dataacess.Usuario;

public class NotificaDao extends GenericDAO<Notifica> {

	public NotificaDao() {
		super(Notifica.class);

	}

	public NotificaDao(EntityManager entityManager) {
		super(Notifica.class, entityManager);
	}


	public ArrayList<Notifica> findbyImei(Date data1, Date data2, String imei) {
		ArrayList<Notifica> noti = null;
		String hql = "FROM Notifica WHERE data >= ? AND data <= ? AND imei = ? order by data";

		EntityManager entityManager = getEntityManager();
		Query query = entityManager.createQuery(hql);
		query.setParameter(1, data1);
		query.setParameter(2, data2);
		query.setParameter(3, imei);

		try {
			noti = (ArrayList<Notifica>) query.getResultList();

			return noti;

		} catch (RuntimeException e) {

			return noti = null;

		}
	}

	public ArrayList<Notifica> findbyImeiRast(String rast) {
		ArrayList<Notifica> noti = null;
		String hql = "FROM Notifica WHERE imei = ?";

		EntityManager entityManager = getEntityManager();
		Query query = entityManager.createQuery(hql);
		query.setParameter(1, rast);

		try {
			noti = (ArrayList<Notifica>) query.getResultList();

			return noti;

		} catch (RuntimeException e) {

			return noti = null;

		}
	}



}
